/***************************************************************************//**
 * @file GUI/GraphicsPFD.h
 * @author  Marek M. Cel <marekcel@mscsim.org>
 *
 * @section LICENSE
 *
 * Copyright (C) 2013 Marek M. Cel
 *
 * This file is part of MScSim. You can redistribute and modify it under
 * the terms of GNU General Public License as published by the Free Software
 * Foundation; either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.
 * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Further information about the GNU General Public License can also be found
 * on the world wide web at http://www.gnu.org.
 ******************************************************************************/
#ifndef GRAPHICS_PFD_H
#define GRAPHICS_PFD_H

////////////////////////////////////////////////////////////////////////////////

#include <QGraphicsView>
#include <QGraphicsSvgItem>

#include "PFD_ADI.h"
#include "PFD_ALT.h"
#include "PFD_ASI.h"
#include "PFD_HSI.h"
#include "PFD_VSI.h"

////////////////////////////////////////////////////////////////////////////////

/**
 * This class provides Primary Fligh Display widget.
 * Symbols are inspired by various PFD's (mostly Rockwell-Collins). */
class GraphicsPFD : public QGraphicsView
{
    Q_OBJECT

public:

    /** Constructor. */
    explicit GraphicsPFD( QWidget *parent = 0 );

    /** Destructor. */
    virtual ~GraphicsPFD();

    /** */
    void reinit();

    /** */
    void update();

    /** @param roll angle [deg] */
    inline void setRoll( float roll )
    {
        m_adi->setRoll( roll );
    }

    /** @param pitch angle [deg] */
    inline void setPitch( float pitch )
    {
        m_adi->setPitch( pitch );
    }

    /**
     * @param angle of attack [deg]
     * @param angle of sideslip [deg] */
    inline void setFlightPathMarker( float aoa, float sideslip )
    {
        m_adi->setFlightPathMarker( aoa, sideslip );
    }

    /** @param normalized slip or skid (range from -1.0 to 1.0) */
    inline void setSlipSkid( float slipSkid )
    {
        m_adi->setSlipSkid( slipSkid );
    }

    /**
     * @param normalized turn rate (range from -1.0 to 1.0),
     * hash marks positions are set to be -0.5 and 0.5 */
    inline void setTurnRate( float turnRate )
    {
        m_adi->setTurnRate( turnRate );
    }

    /** @param altitude (dimensionless numeric value) */
    inline void setAltitude( float altitude )
    {
        m_alt->setAltitude( altitude );
    }

    /** @param airspeed (dimensionless numeric value) */
    inline void setAirspeed( float airspeed )
    {
        m_asi->setAirspeed( airspeed );
    }

    /** @param Mach number */
    inline void setMachNo( float machNo )
    {
        m_asi->setMachNo( machNo );
    }

    /** @param heading [deg] */
    inline void setHeading( float heading )
    {
        m_hsi->setHeading( heading );
    }

    /** @param climb rate (dimensionless numeric value)  */
    inline void setClimbRate( float climbRate )
    {
        m_vsi->setClimbRate( climbRate );
    }

protected:

    /** */
    void resizeEvent( QResizeEvent *event );

private:

    QGraphicsScene *m_scene;        ///< graphics scene

    PFD_ADI *m_adi;
    PFD_ALT *m_alt;
    PFD_ASI *m_asi;
    PFD_HSI *m_hsi;
    PFD_VSI *m_vsi;

    QGraphicsSvgItem *m_itemBack;   ///< PFD background
    QGraphicsSvgItem *m_itemMask;   ///< PFD mask

    float m_scaleX; ///<
    float m_scaleY; ///<

    const int m_originalHeight;     ///< [px]
    const int m_originalWidth;      ///< [px]

    const int m_backZ;
    const int m_maskZ;

    /** */
    void init();

    /** */
    void reset();

    /** */
    void updateView();
};

////////////////////////////////////////////////////////////////////////////////

#endif // GRAPHICS_PFD_H
